#!/usr/local/bin/perl

#usage of foreach loop in perl


@text_list = ("abcd","pqrs","xyz");
@num_list = (1, 2, 3);

foreach $item (@text_list) {
    if ( ($item eq "abcd") || ($item ne "xyz") ) {  # if item equals "abcd" or item not equal to "xyz"
        print $item . "\n";         # prints "abcd" and "pqrs" followed by a new line each
    } elsif ($item eq "pqrs") {
        print $item . "\n";         # prints "pqrs" followed by a new line
    }
}

for ($i = 0; $i <= 2; $i++) {       # ==, != work for numerical data
    print $text_list[$i] . "\n";
}

$a = "abcd";
while ( $a ne "a" ) {
    chop ($a);    # removes the last character of the string
}                 # do { ... } while ()  is also supported
print $a . "\n";
